import { useTagStore } from '@/stores/layout'
import { useRoute, useRouter } from 'vue-router'

export default function useGoBack(backPath: string) {
  const route = useRoute()
  const router = useRouter()
  const tagStore = useTagStore()
  const regExp = new RegExp(`${backPath}(.*)`)

  return () => {
    tagStore.closeTag(route.fullPath)
    router.push(route.fullPath.replace(regExp, ''))
  }
}
